package com.aspose.cells;

import java.util.ArrayList;
import java.util.HashMap;

class zaem {
   private Worksheet a = null;
   private ArrayList b = null;
   private ArrayList c = null;
   private ArrayList d = null;
   private ArrayList e = null;
   private int f = 0;
   private int g = 0;
   private int h = -1;
   private ArrayList i = new ArrayList();
   private zaeh j = null;
   private HashMap k;
   private String l = null;
   private String m;

   zaem(zaeh var1, Worksheet var2, zafg var3, String var4, String var5, String var6, String var7, HtmlSaveOptions var8) throws Exception {
      this.k = new HashMap(var2.getCells().getColumns().getCount());
      this.a = var2;
      this.j = var1;
      this.g = this.f();
      this.h = this.g();
      this.k();
      this.i();
      this.j();
      this.h();
      this.a(this.a);
      if (this.j.n != null || this.j.c().getExportImagesAsBase64()) {
         this.a(var3, var4, var5, var6, var7, var8);
      }

      this.m = var5;
   }

   void a(Worksheet var1) {
      if (var1.isVisible()) {
         int var2 = var1.getPivotTables().getCount();
         PivotTable var3 = null;

         for(int var4 = 0; var4 < var2; ++var4) {
            var3 = var1.getPivotTables().get(var4);
            if (!var3.ah) {
               var3.a();
            }
         }
      }

   }

   Worksheet a() {
      return this.a;
   }

   int b() {
      return this.h;
   }

   int c() {
      return this.g;
   }

   private void a(zafg var1, String var2, String var3, String var4, String var5, HtmlSaveOptions var6) throws Exception {
      ShapeCollection var7 = this.a.t();
      if (var7 != null && var7.getCount() != 0) {
         String var8 = "";
         IExportObjectListener var9 = this.j.c().getExportObjectListener();
         if (var9 == null) {
            var8 = this.j.b(var2);
         }

         this.e = new ArrayList();
         HashMap var10 = this.j.f();
         int var11 = var7.getCount();

         int var12;
         for(var12 = 0; var12 < var11; ++var12) {
            this.l = null;
            Shape var13 = var7.get(var12);
            if (!var13.S() && (var13.getWidth() > 0 || var13.getHeight() > 0)) {
               String var14 = null;
               Object var15;
               if (var9 != null) {
                  var15 = var9.exportObject(new ExportObjectEvent(var13));
                  if (var15 != null && var15 instanceof String) {
                     var14 = (String)var15;
                  }
               } else {
                  Object var16;
                  switch(var13.getMsoDrawingType()) {
                  case 0:
                  case 1:
                  case 2:
                  case 3:
                  case 4:
                  case 5:
                  case 6:
                  case 7:
                  case 9:
                  case 11:
                  case 12:
                  case 14:
                  case 15:
                  case 16:
                  case 17:
                  case 18:
                  case 19:
                  case 20:
                  case 30:
                     var14 = zaff.e(var13.getMsoDrawingType()) + this.a.getName() + "_" + zase.y(var12) + ".";
                     if (var6.getImageOptions().getImageFormat() == ImageFormat.getEmf()) {
                        var14 = var14 + "png";
                     } else {
                        var14 = var14 + a(var6.getImageOptions().getImageFormat());
                     }

                     var14 = zaff.d(var14);

                     try {
                        this.a(var1, var13, var6, var8, var3, var14);
                     } catch (Exception var18) {
                        continue;
                     }

                     var14 = var8 + var14;
                     break;
                  case 8:
                     if (zaff.a((Picture)var13)) {
                        var14 = zaff.e(var13.getMsoDrawingType()) + this.a.getName() + "_" + zase.y(var12) + ".";
                        if (var6.getImageOptions().getImageFormat() == ImageFormat.getEmf()) {
                           var14 = var14 + "png";
                        } else {
                           var14 = var14 + a(var6.getImageOptions().getImageFormat());
                        }

                        var14 = zaff.d(var14);

                        try {
                           this.a(var1, var13, var6, var8, var3, var14);
                        } catch (Exception var21) {
                           continue;
                        }

                        var14 = var8 + var14;
                     } else if (var10 != null && var10.size() > 0) {
                        var15 = var10.get(((Picture)var13).b() - 1);
                        if (var15 != null) {
                           var14 = (String)var15;
                           if (var6.getImageOptions().d && ((Picture)var13).getImageFormat() != var6.getImageOptions().getImageFormat()) {
                              var14 = zaff.e(var13.getMsoDrawingType()) + this.a.getName() + "_" + zase.y(var12) + "." + a(var6.getImageOptions().getImageFormat());
                              var14 = zaff.d(var14);

                              try {
                                 this.a(var1, var13, var6, var8, var3, var14);
                              } catch (Exception var20) {
                                 continue;
                              }

                              var14 = var8 + var14;
                           } else {
                              var16 = this.j.g().get(((Picture)var13).b() - 1);
                              if (var16 != null) {
                                 this.l = (String)var16;
                              }
                           }
                        }
                     }
                     break;
                  case 10:
                  case 13:
                  case 21:
                  case 22:
                  case 23:
                  case 26:
                  case 27:
                  case 28:
                  case 29:
                  default:
                     var14 = zaff.e(var13.getMsoDrawingType()) + this.a.getName() + "_" + zase.y(var12) + ".";
                     if (var6.getImageOptions().getImageFormat() == ImageFormat.getEmf()) {
                        var14 = var14 + "png";
                     } else {
                        var14 = var14 + a(var6.getImageOptions().getImageFormat());
                     }

                     var14 = zaff.d(var14);

                     try {
                        this.a(var1, var13, var6, var8, var3, var14);
                     } catch (Exception var17) {
                        continue;
                     }

                     var14 = var8 + var14;
                     break;
                  case 24:
                     if (var10 != null && var10.size() > 0) {
                        var15 = var10.get(((OleObject)var13).e() - 1);
                        if (var15 != null) {
                           var14 = (String)var15;
                           if ((var14.endsWith(".emf") || var14.endsWith(".EMF")) && var6.getImageOptions().getImageFormat() != ImageFormat.getEmf()) {
                              var14 = zaff.e(var13.getMsoDrawingType()) + this.a.getName() + "_" + zase.y(var12) + "." + a(var6.getImageOptions().getImageFormat());
                              var14 = zaff.d(var14);

                              try {
                                 this.a(var1, var13, var6, var8, var3, var14);
                              } catch (Exception var19) {
                                 continue;
                              }

                              var14 = var8 + var14;
                           } else {
                              var16 = this.j.g().get(((OleObject)var13).e() - 1);
                              if (var16 != null) {
                                 this.l = (String)var16;
                              }
                           }
                        }
                     }
                  case 25:
                  }
               }

               if (var14 != null) {
                  if (this.l != null) {
                     var14 = this.l;
                  }

                  com.aspose.cells.b.a.a.ze.a(this.e, (Object)(new zaek(var13, var12, var14)));
               }
            }
         }

         var12 = this.e.size();
         zaek[] var22 = new zaek[var12];

         for(int var25 = 0; var25 < var12; ++var25) {
            zaek var23 = (zaek)this.e.get(var25);
            var22[var25] = var23;
         }

         zael var26 = new zael();
         com.aspose.cells.b.a.za.a(var22, var26);
         this.e = new ArrayList(var12);

         for(int var24 = 0; var24 < var12; ++var24) {
            com.aspose.cells.b.a.a.ze.a(this.e, (Object)var22[var24]);
         }

      }
   }

   private void a(zafg var1, Shape var2, HtmlSaveOptions var3, String var4, String var5, String var6) throws Exception {
      ImageFormat var7 = var3.getImageOptions().getImageFormat() == ImageFormat.getEmf() ? ImageFormat.getPng() : var3.getImageOptions().getImageFormat();
      if (var1.a() == 12) {
         if (!var3.getExportImagesAsBase64()) {
            StreamProviderOptions var8 = new StreamProviderOptions();
            var8.a = this.j.o + "/" + var6;
            this.j.u.initStream(var8);
            this.l = var8.b;
            var2.a(var8.c, var3.getImageOptions());
            this.j.u.closeStream(var8);
         }
      } else {
         com.aspose.cells.b.a.d.zh var11 = new com.aspose.cells.b.a.d.zh();
         ImageOrPrintOptions var9 = new ImageOrPrintOptions();
         var9.setChartImageType(var7);
         var9.setImageFormat(var7);
         var2.a((com.aspose.cells.b.a.d.zm)var11, (ImageOrPrintOptions)var9);
         byte[] var10 = var11.o();
         var1.b().put(var5 + com.aspose.cells.b.a.zv.a(var4, "\\", "/") + var6, var10);
      }

   }

   static String a(ImageFormat var0) {
      if (var0 == ImageFormat.getBmp()) {
         return "bmp";
      } else if (var0 == ImageFormat.getEmf()) {
         return "emf";
      } else if (var0 == ImageFormat.getExif()) {
         return "exif";
      } else if (var0 == ImageFormat.getGif()) {
         return "gif";
      } else if (var0 == ImageFormat.getJpeg()) {
         return "jpg";
      } else if (var0 == ImageFormat.getPng()) {
         return "png";
      } else if (var0 == ImageFormat.getTiff()) {
         return "tiff";
      } else {
         return var0 == ImageFormat.getWmf() ? "wmf" : "png";
      }
   }

   private int f() {
      Cells var1 = this.a.getCells();
      int var2 = var1.d(0);
      if (var1.getRows().getCount() > 0) {
         int var3 = var1.getRows().getRowByIndex(var1.getRows().getCount() - 1).getIndex();
         if (var3 > var2) {
            var2 = var3;
         }
      }

      zani var8 = this.a.getCells().q();
      if (var8 != null && var8.getCount() > 0) {
         CellArea var4 = var8.a(var8.getCount() - 1);
         if (var2 < var4.EndRow && var4.EndRow <= this.a.getCells().getMaxRow()) {
            var2 = var4.EndRow;
         }
      }

      ShapeCollection var9 = this.a.t();
      if (var9 != null && var9.getCount() > 0) {
         for(int var5 = 0; var5 < var9.getCount(); ++var5) {
            Shape var6 = var9.get(var5);
            int var7 = var6.getLowerRightRow();
            if (var7 > var2) {
               var2 = var7;
            }
         }
      }

      return var2;
   }

   private int g() throws Exception {
      Cells var1 = this.a.getCells();
      int var2 = 0;

      int var5;
      for(int var3 = 0; var3 < var1.getRows().getCount(); ++var3) {
         Row var4 = var1.getRows().getRowByIndex(var3);

         for(var5 = var4.a() - 1; var5 >= 0; --var5) {
            Cell var6 = var4.getCellByIndex(var5);
            Style var7 = var6.p();
            if (var6.getType() != 3) {
               int var8 = var6.getColumn();
               if (!var7.isTextWrapped() && var6.getType() == 5) {
                  String var9 = var6.getStringValue();
                  new StringBuilder(var9.length() + 100);
                  int var11 = 0;
                  if (var6.isRichText()) {
                     ArrayList var12 = var6.J();

                     for(int var13 = 0; var13 < var12.size(); ++var13) {
                        zot var14 = (zot)var12.get(var13);
                        var14.c = this.j.d().a(var14.b, var14.a);
                        var11 += var14.c;
                     }
                  } else {
                     var11 = this.j.d().a(var6.p(), var9);
                  }

                  int var23 = this.a(var8);
                  if (var11 > var23) {
                     Cell var24 = null;
                     if (var6 != null && var6.getColumn() < 255) {
                        var24 = this.a.getCells().get(var6.getRow(), var6.getColumn() + 1);
                     }

                     int var25 = 0;

                     for(Column var15 = null; zaff.b(var6.getDisplayStyle(), var24.getDisplayStyle()) && null == var24.getValue(); var24 = this.a.getCells().get(var24.getRow(), var24.getColumn() + 1)) {
                        var15 = this.a.getCells().checkColumn(var24.getColumn());
                        if (null == var15) {
                           var25 += this.a.getCells().getStandardWidthPixels();
                        } else {
                           var25 += var15.a();
                        }

                        var15 = null;
                        ++var8;
                        if (var25 + var23 > var11 || var24 == null || var24.getColumn() >= 255) {
                           break;
                        }
                     }
                  }
               }

               if (var2 < var8) {
                  var2 = var8;
               }
               break;
            }

            if (var7 != null && zaff.a(var7, this.j.h())) {
               if (var2 < var6.getColumn()) {
                  var2 = var6.getColumn();
               }
               break;
            }
         }
      }

      zani var16 = this.a.getCells().q();
      if (var16 != null) {
         for(int var17 = 0; var17 < var16.getCount(); ++var17) {
            CellArea var19 = var16.a(var17);
            if (var2 < var19.EndColumn) {
               var2 = var19.EndColumn;
            }
         }
      }

      ShapeCollection var18 = this.a.t();
      if (var18 != null && var18.getCount() > 0) {
         boolean var20 = false;

         for(int var21 = 0; var21 < var18.getCount(); ++var21) {
            Shape var22 = var18.get(var21);
            var5 = var22.getLowerRightColumn();
            if (var5 > var2) {
               var2 = var5;
            }
         }
      }

      return var2;
   }

   private zaeg a(Column var1) {
      zaeg var2 = new zaeg();
      var2.a = var1.getIndex();
      var2.e = var1.c();
      var2.f = var1.f();
      var2.c = this.a(var1.getIndex());
      if (var1.isHidden() || var1.g()) {
         var2.d = true;
         var2.c = 0;
      }

      if (var1.c() == 15 && var2.c == this.a.getCells().getStandardWidthPixels()) {
         var2.g = true;
      }

      return var2;
   }

   private zaeg b(int var1) {
      zaeg var2 = new zaeg();
      var2.a = var1;
      var2.e = 15;
      var2.f = this.a.getWorkbook().getDefaultStyle();
      var2.c = this.a.getCells().getStandardWidthPixels();
      var2.g = true;
      return var2;
   }

   private zaeg c(int var1) {
      int var2 = this.a.getCells().getColumns().e(var1);
      if (var2 < 0) {
         return this.b(var1);
      } else {
         Column var3 = this.a.getCells().getColumns().getColumnByIndex(var2);
         return this.a(var3);
      }
   }

   private void h() {
      zaeg var1 = null;

      for(int var2 = 0; var2 <= this.h; ++var2) {
         zaeg var3 = this.c(var2);
         if (var1 != null && var1.a(var3)) {
            ++var1.b;
         } else {
            if (var1 != null) {
               com.aspose.cells.b.a.a.ze.a(this.i, (Object)var1);
            }

            var1 = var3;
         }
      }

      if (var1 != null) {
         com.aspose.cells.b.a.a.ze.a(this.i, (Object)var1);
      }

   }

   ArrayList d() {
      return this.i;
   }

   long e() {
      long var1 = 0L;

      for(int var3 = 0; var3 <= this.h; ++var3) {
         var1 += (long)this.a(var3);
      }

      return var1;
   }

   private void i() {
      HyperlinkCollection var1 = this.a.getHyperlinks();
      int var2 = var1.getCount();
      if (var2 == 0) {
         this.c = null;
      } else {
         Hyperlink[] var3 = new Hyperlink[var2];

         for(int var4 = 0; var4 < var2; ++var4) {
            Hyperlink var5 = var1.get(var4);
            var3[var4] = var5;
         }

         zaei var6 = new zaei();
         com.aspose.cells.b.a.za.a(var3, var6);
         this.c = new ArrayList(var2);

         for(int var7 = 0; var7 < var2; ++var7) {
            com.aspose.cells.b.a.a.ze.a(this.c, (Object)var3[var7]);
         }

      }
   }

   private void j() {
      ArrayList var1 = this.j.i();
      int var2 = var1.size();
      if (var2 == 0) {
         this.d = null;
      } else {
         CellArea[] var3 = new CellArea[var2];
         int var4 = 0;

         for(int var5 = 0; var5 < var2; ++var5) {
            String var6 = null;
            CellArea var7 = null;
            Hyperlink var8 = (Hyperlink)var1.get(var5);
            String[] var9 = new String[]{var6};
            CellArea[] var10 = new CellArea[]{var7};
            boolean var11 = zaff.a(this.j.g.getWorksheets(), var8, var9, var10);
            var6 = var9[0];
            var7 = var10[0];
            if (var11 && com.aspose.cells.b.a.zv.b(var6, this.a.getName())) {
               var3[var4] = var7;
               ++var4;
            }
         }

         if (var4 != 0) {
            zaef var12 = new zaef();
            com.aspose.cells.b.a.za.a(var3, 0, var4, var12);
            this.d = new ArrayList(var4);

            for(int var13 = 0; var13 < var4; ++var13) {
               com.aspose.cells.b.a.a.ze.a(this.d, (Object)var3[var13]);
            }

         }
      }
   }

   private void k() {
      zani var1 = this.a.getCells().q();
      int var2 = var1.getCount();
      if (var2 == 0) {
         this.b = null;
      } else {
         CellArea[] var3 = new CellArea[var2];

         for(int var4 = 0; var4 < var2; ++var4) {
            CellArea var5 = var1.a(var4);
            var3[var4] = var5;
         }

         zaef var6 = new zaef();
         com.aspose.cells.b.a.za.a(var3, var6);
         this.b = new ArrayList(var2);

         for(int var7 = 0; var7 < var2; ++var7) {
            com.aspose.cells.b.a.a.ze.a(this.b, (Object)var3[var7]);
         }

      }
   }

   private void a(zaej var1) {
      if (this.b != null) {
         int var2 = var1.d();
         int var3 = this.b.size();
         var1.a = new ArrayList(var3);
         ArrayList var4 = new ArrayList(var3);

         int var5;
         for(var5 = 0; var5 < var3; ++var5) {
            CellArea var6 = (CellArea)this.b.get(var5);
            if (var2 >= var6.StartRow && var2 <= var6.EndRow) {
               com.aspose.cells.b.a.a.ze.a(var1.a, (Object)var6);
            } else {
               if (var2 < var6.StartRow) {
                  break;
               }

               if (var2 > var6.EndRow) {
                  com.aspose.cells.b.a.a.ze.a(var4, (Object)var6);
               }
            }
         }

         for(var5 = 0; var5 < var4.size(); ++var5) {
            this.b.remove(var4.get(var5));
         }

         if (this.b.size() == 0) {
            this.b = null;
         }

      }
   }

   private void b(zaej var1) {
      if (this.d != null) {
         int var2 = var1.d();
         int var3 = this.d.size();
         var1.c = new ArrayList(var3);
         ArrayList var4 = new ArrayList(var3);

         int var5;
         for(var5 = 0; var5 < var3; ++var5) {
            CellArea var6 = (CellArea)this.d.get(var5);
            if (var2 >= var6.StartRow && var2 <= var6.EndRow) {
               com.aspose.cells.b.a.a.ze.a(var1.c, (Object)var6);
            } else {
               if (var2 < var6.StartRow) {
                  break;
               }

               if (var2 > var6.EndRow) {
                  com.aspose.cells.b.a.a.ze.a(var4, (Object)var6);
               }
            }
         }

         for(var5 = 0; var5 < var4.size(); ++var5) {
            this.d.remove(var4.get(var5));
         }

         if (this.d.size() == 0) {
            this.d = null;
         }

      }
   }

   private void c(zaej var1) {
      if (this.c != null) {
         int var2 = var1.d();
         int var3 = this.c.size();
         var1.b = new ArrayList(var3);
         ArrayList var4 = new ArrayList(var3);

         int var5;
         for(var5 = 0; var5 < var3; ++var5) {
            Hyperlink var6 = (Hyperlink)this.c.get(var5);
            CellArea var7 = var6.getArea();
            if (var2 >= var7.StartRow && var2 <= var7.EndRow) {
               com.aspose.cells.b.a.a.ze.a(var1.b, (Object)var6);
            } else {
               if (var2 < var7.StartRow) {
                  break;
               }

               if (var2 > var7.EndRow) {
                  com.aspose.cells.b.a.a.ze.a(var4, (Object)var6);
               }
            }
         }

         for(var5 = 0; var5 < var4.size(); ++var5) {
            this.c.remove(var4.get(var5));
         }

         if (this.c.size() == 0) {
            this.c = null;
         }

      }
   }

   private void d(zaej var1) {
      if (this.e != null) {
         int var2 = var1.d();
         int var3 = this.e.size();
         var1.d = new ArrayList(var3);
         ArrayList var4 = new ArrayList(var3);

         int var5;
         for(var5 = 0; var5 < var3; ++var5) {
            zaek var6 = (zaek)this.e.get(var5);
            if (var2 == var6.a()) {
               com.aspose.cells.b.a.a.ze.a(var4, (Object)var6);
               com.aspose.cells.b.a.a.ze.a(var1.d, (Object)var6);
            } else if (var2 < var6.a()) {
               if (var1.a == null) {
                  break;
               }

               for(int var7 = 0; var7 < var1.a.size(); ++var7) {
                  CellArea var8 = (CellArea)var1.a.get(var7);
                  if (var8.StartRow <= var6.a() && (var8.EndRow >= var6.b() || var8.EndRow >= var6.a() && var8.EndRow < var6.b()) && var8.StartColumn <= var6.c() && (var8.EndColumn >= var6.d() || var8.EndColumn < var6.d() && var8.EndColumn >= var6.c())) {
                     com.aspose.cells.b.a.a.ze.a(var4, (Object)var6);
                     com.aspose.cells.b.a.a.ze.a(var1.d, (Object)var6);
                  }
               }
            } else if (var2 > var6.a()) {
               com.aspose.cells.b.a.a.ze.a(var4, (Object)var6);
            }
         }

         for(var5 = 0; var5 < var4.size(); ++var5) {
            this.e.remove(var4.get(var5));
         }

         if (this.e.size() == 0) {
            this.e = null;
         }

      }
   }

   zaej a(Row var1, int var2) {
      zaej var3 = new zaej(this.j, this, var1, var2, this.j.c(), this.m);
      this.a(var3);
      this.c(var3);
      this.b(var3);
      this.d(var3);
      return var3;
   }

   int a(int var1, int var2) {
      int var3 = 0;

      for(int var4 = var1; var4 < var2; ++var4) {
         var3 += this.a(var4);
      }

      return var3;
   }

   int a(int var1) {
      Object var2 = this.k.get(var1);
      if (var2 != null) {
         return (Integer)var2;
      } else {
         int var3 = this.a.getCells().getColumnWidthPixel(var1);
         this.k.put(var1, var3);
         return var3;
      }
   }
}
